//package com.hnfnu.service;
//
//import com.hnfnu.config.ContractConfig;
//import com.hnfnu.config.SystemConfig;
//import lombok.Data;
//import lombok.extern.slf4j.Slf4j;
//import org.fisco.bcos.sdk.v3.client.Client;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import javax.annotation.PostConstruct;
//import java.util.Arrays;
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//
//@Configuration
//@Data
//@Slf4j
//public class ServiceManager {
//  @Autowired
//  private SystemConfig systemConfig;
//
//  @Autowired
//  private ContractConfig contractConfig;
//
//  @Autowired
//  private Client client;
//
//  List<String> hexPrivateKeyList;
//
//  @PostConstruct
//  public void init() {
//    hexPrivateKeyList = Arrays.asList(this.systemConfig.getHexPrivateKey().split(","));
//  }
//
//  /**
//   * @notice: must use @Qualifier("DonationRecordService") with @Autowired to get this Bean
//   */
//  @Bean("DonationRecordService")
//  public Map<String, DonationRecordService> initDonationRecordServiceManager() throws Exception {
//    Map<String, DonationRecordService> serviceMap = new ConcurrentHashMap<>(this.hexPrivateKeyList.size());
//    for (int i = 0; i < this.hexPrivateKeyList.size(); i++) {
//    	String privateKey = this.hexPrivateKeyList.get(i);
//    	if (privateKey.startsWith("0x") || privateKey.startsWith("0X")) {
//    		privateKey = privateKey.substring(2);
//    	}
//    	if (privateKey.isEmpty()) {
//    		continue;
//    	}
//    	org.fisco.bcos.sdk.v3.crypto.CryptoSuite cryptoSuite = new org.fisco.bcos.sdk.v3.crypto.CryptoSuite(this.client.getCryptoType());
//    	org.fisco.bcos.sdk.v3.crypto.keypair.CryptoKeyPair cryptoKeyPair = cryptoSuite.getKeyPairFactory().createKeyPair(privateKey);
//    	String userAddress = cryptoKeyPair.getAddress();
//    	log.info("++++++++hexPrivateKeyList[{}]:{},userAddress:{}", i, privateKey, userAddress);
//    	DonationRecordService donationRecordService = new DonationRecordService();
//    	donationRecordService.setAddress(this.contractConfig.getDonationRecordAddress());
//    	donationRecordService.setClient(this.client);
//    	org.fisco.bcos.sdk.v3.transaction.manager.AssembleTransactionProcessor txProcessor =
//    		org.fisco.bcos.sdk.v3.transaction.manager.TransactionProcessorFactory.createAssembleTransactionProcessor(this.client, cryptoKeyPair);
//    	donationRecordService.setTxProcessor(txProcessor);
//    	serviceMap.put(userAddress, donationRecordService);
//    }
//    log.info("++++++++DonationRecordService map:{}", serviceMap);
//    return serviceMap;
//  }
//
//
//    @Bean("DisburseRecordService")
//    public Map<String, DisburseRecordService> initDisburseRecordServiceManager() throws Exception {
//        Map<String, DisburseRecordService> serviceMap = new ConcurrentHashMap<>(this.hexPrivateKeyList.size());
//        for (int i = 0; i < this.hexPrivateKeyList.size(); i++) {
//            String privateKey = this.hexPrivateKeyList.get(i);
//            if (privateKey.startsWith("0x") || privateKey.startsWith("0X")) {
//                privateKey = privateKey.substring(2);
//            }
//            if (privateKey.isEmpty()) {
//                continue;
//            }
//            org.fisco.bcos.sdk.v3.crypto.CryptoSuite cryptoSuite = new org.fisco.bcos.sdk.v3.crypto.CryptoSuite(this.client.getCryptoType());
//            org.fisco.bcos.sdk.v3.crypto.keypair.CryptoKeyPair cryptoKeyPair = cryptoSuite.getKeyPairFactory().createKeyPair(privateKey);
//            String userAddress = cryptoKeyPair.getAddress();
//            log.info("++++++++hexPrivateKeyList[{}]:{},userAddress:{}", i, privateKey, userAddress);
//            DisburseRecordService disburseRecordService = new DisburseRecordService();
//            disburseRecordService.setAddress(this.contractConfig.getDisburseRecordAddress());
//            disburseRecordService.setClient(this.client);
//            org.fisco.bcos.sdk.v3.transaction.manager.AssembleTransactionProcessor txProcessor =
//                    org.fisco.bcos.sdk.v3.transaction.manager.TransactionProcessorFactory.createAssembleTransactionProcessor(this.client, cryptoKeyPair);
//            disburseRecordService.setTxProcessor(txProcessor);
//            serviceMap.put(userAddress, disburseRecordService);
//        }
//        log.info("++++++++DisburseRecordService map:{}", serviceMap);
//        return serviceMap;
//    }
//}
